// pages/account/index.js
var app = getApp(), fetchApi = require("../../utils/httpPost.js"),
formatTime = require("../../component/common.js")
import Toast from '../../component/vant/toast/toast';
import Dialog from '../../component/vant/dialog/dialog';
import { hexMD5 } from '../../utils/md5.js';
const CryptoJS = require("../../utils/aesUtil.js")
const format = rate => Math.min(Math.max(rate, 0), 100);
Page({
  /**
   * 页面的初始数据
   */
  data: {
    phoneNum:'去绑定',
    name:'',
    mark:'',
    submitState:false,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.onHttpInit();
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    var that = this
    fetchApi.httpPost('/wxUser/getAccountInfo', {}, function (res) {
      console.log("账号绑定 数据", res)
      if(res.data.code == 0){
        that.data.phoneNum = res.data.data.phone_num;
        that.setData({
          is_has_pay_pwd: res.data.data.is_has_pay_pwd,
          phoneNum: res.data.data.phone_num!=undefined &&  res.data.data.phone_num!='' ? res.data.data.phone_num : '去绑定',
        })
      }
      that.setData({
        netWork: true,
      })
    }, function () {
        that.setData({ netWork: false, hasData: false })
    })
  },
  bindInput(e){
    var type = e.currentTarget.dataset.type;
    if(type == 'name'){
        this.data.name = e.detail;
    } else if(type == 'phone'){
        this.data.phoneNum = e.detail;
    } else if(type == 'mark'){
        this.data.mark = e.detail;
    }
  },
  goSubmit(){
    if(this.data.name == ''){
      Toast.fail("请输入姓名");
      return ;
    }
    if(this.data.phoneNum == ''){
      Toast.fail("请输入电话");
      return ;
    }
    if(this.data.mark == ''){
        Toast.fail("请输入留言信息");
      return ;
    }

    this.onHttpUpdatePwd();
  },
  onHttpUpdatePwd(){
    var that = this;
    fetchApi.httpPost('/wxUser/business/cooperation', {
      phone_num:that.data.phoneNum,
      real_name: that.data.name,
      remark: that.data.mark,
    }, function (res) {
      console.log("商务合作上报", res)
      if(res.data.code == 0){
        Toast.success(res.data.msg)
        setTimeout(function(){
          wx.navigateBack({
            delta: -1,
          })
        },1000)
      }else{
        Toast.fail(res.data.msg)
      }
    }, function () {
        that.setData({ netWork: false, hasData: false })
    })
  },
})